<?php
/**
 * This class is a simple hash used to store page dependancy files
 * 
 * @package System_View
 * @subpackage System_View_Asset
 * @author Mark Henderson
 */
class System_View_Asset_File{
    /**
     * holds an instance of the class
     * 
     * @var System_View_Asset_File
     * @static
     * @access private
     */
    private static $_instance = false;
    
    /**
     * array used to store the javascript files
     * 
     * @var array
     * @static
     * @access private
     */
    private static $_javascript = array();
    
    /**
     * array used to store the css files
     * 
     * @var array
     * @static
     * @access private
     */
    private static $_css = array();
    
    /**
     * private constructor to allow for singleton
     */
    private function __construct(){}
    
    /**
     * returns an instance of this object
     *
     * @access public
     * @static
     * @return System_View_Asset_File
     */
    public static function getInstance(){
        if(!self::$_instance) {
            self::$_instance = new self();
        }
        
        return self::$_instance;
    }
    
    /**
     * sets dependancy files
     *
     * @param string $type -- the type of dependancy; js or css
     * @param array $files -- an array containing all of the file names and paths relative to $_SERVER['DOCUMENT_ROOT'] /$type
     * @access public
     * @static
     * @throws Exception -- if no type is set or no files are passed in
     * @return null
     */
    public static function set($type = '', $files){
        if(trim($type) == '' || !count($files)){
            throw new Exception('You have to pass in a type or some files.');
        }else{
            switch($type){
                case 'css':
                    self::$_css = $files;
                    break;
                
                case 'js':
                    self::$_javascript = $files;
            }
        }
    }
    
    /**
     * returns a specific set of file dependancies 
     *
     * @param string $type -- the file set that you're looking through
     * @param string $name -- the name of the file set
     * @access public
     * @static
     * @return array
     */
    public static function get($type = '', $name = ''){
        $return = array();
        $check  = array();
        
        switch($type){
            case 'css':
                $check = self::$_css;
                break;
            
            case 'js':
                $check = self::$_javascript;
                break;
        }
        
        if(isset($check[$name])){
            $return = $check[$name];
        }
        
        return $return;
    }
}